import { BadgeConditionType, BadgeType } from "@/constants/common"

// 用户相关类型
export interface User {
  id: number
  username: string
  email: string
  realName?: string
  phone?: string
  status: 'ACTIVE' | 'INACTIVE' | 'BANNED'
  createdAt: string
  updatedAt: string
  roles?: Role[]
  userRoles?: UserRole[]
  avatar?: string
  lastLoginAt?: string
  permissions?: string[]
}

export interface UserRole {
  id: number
  userId: number
  roleId: number
  role: Role
}

export interface CreateUserRequest {
  username: string
  email: string
  password: string
  realName?: string
  phone?: string
  roleIds?: number[]
}

export interface UpdateUserRequest {
  username?: string
  email?: string
  realName?: string
  phone?: string
  status?: 'ACTIVE' | 'INACTIVE' | 'BANNED'
  roleIds?: number[]
}

// 角色相关类型
export interface Role {
  id: number
  name: string
  description?: string
  status: 'ACTIVE' | 'INACTIVE'
  createdAt: string
  updatedAt: string
  permissions?: Permission[]
  rolePermissions?: RolePermission[]
  userCount?: number
  permissionCount?: number
  _count?: {
    userRoles: number
    rolePermissions: number
  }
}

export interface RolePermission {
  id: number
  roleId: number
  permissionId: number
  permission: Permission
}

export interface CreateRoleRequest {
  name: string
  description?: string
  status?: 'ACTIVE' | 'INACTIVE'
  permissionIds?: number[]
}

export interface UpdateRoleRequest {
  name?: string
  description?: string
  status?: 'ACTIVE' | 'INACTIVE'
  permissionIds?: number[]
}

// 权限相关类型
export interface Permission {
  id: number
  name: string
  code: string
  description?: string
  module?: string
  action?: string
  resource?: string
  createdAt: string
  updatedAt: string
  roleCount?: number
  _count?: {
    rolePermissions: number
  }
}

export interface CreatePermissionRequest {
  name: string
  code: string
  description?: string
  module?: string
  action?: string
  resource?: string
}

export interface UpdatePermissionRequest {
  name?: string
  code?: string
  description?: string
  module?: string
  action?: string
  resource?: string
}

// 系统配置相关类型
export interface SystemConfig {
  id: number
  key: string
  value: string
  description?: string
  type: 'STRING' | 'NUMBER' | 'BOOLEAN' | 'JSON'
  createdAt: string
  updatedAt: string
}

export interface CreateSystemConfigRequest {
  key: string
  value: string
  description?: string
  type?: 'STRING' | 'NUMBER' | 'BOOLEAN' | 'JSON'
}

export interface UpdateSystemConfigRequest {
  key?: string
  value?: string
  description?: string
  type?: 'STRING' | 'NUMBER' | 'BOOLEAN' | 'JSON'
}

// 操作日志相关类型
export interface OperationLog {
  id: number
  action: string
  resource: string
  resourceId?: string
  details?: any
  ipAddress?: string
  userAgent?: string
  createdAt: string
  user?: {
    id: number
    username: string
    realName?: string
    email?: string
  }
  method?: string
  url?: string
  description?: string
  requestData?: any
  responseData?: any
}

// 认证相关类型
export interface LoginRequest {
  username: string
  password: string
}

export interface LoginResponse {
  token: string
  user: User
}

export interface RefreshTokenResponse {
  token: string
}

// 分页相关类型
export interface PaginationParams {
  page?: number
  limit?: number
  search?: string
}

export interface PaginationResponse<T> {
  data: T[]
  pagination: {
    page: number
    limit: number
    total: number
    totalPages: number
    hasNext: boolean
    hasPrev: boolean
  }
  total?: number
  tree?: any[]
}

// API响应类型
export interface ApiResponse<T = any> {
  success: boolean
  code: number
  message: string
  data?: T
  timestamp: string
}

// 统计数据类型
export interface SystemStats {
  users: {
    total: number
    active: number
    banned: number
  }
  roles: {
    total: number
    active: number
  }
  permissions: {
    total: number
  }
  configs: {
    total: number
  }
  logs: {
    total: number
    today: number
    last7Days: Array<{
      date: string
      count: number
    }>
  }
  topUsers: Array<{
    id: number
    username: string
    realName?: string
    operationCount: number
  }>
  topActions: Array<{
    action: string
    count: number
  }>
  // 新增登录趋势统计
  loginTrend?: {
    daily: Array<{
      date: string
      count: number
    }>
    monthly: Array<{
      month: string
      count: number
    }>
    hourly: Array<{
      hour: string
      count: number
    }>
  }
  // 新增用户活跃度统计
  userActivity?: {
    daily: Array<{
      date: string
      count: number
    }>
    monthly: Array<{
      month: string
      count: number
    }>
    hourly: Array<{
      hour: string
      count: number
    }>
  }
  // 添加兼容性字段
  totalUsers?: number
  totalRoles?: number
  totalPermissions?: number
  totalLogs?: number
  activeUsers?: number
  inactiveUsers?: number
  bannedUsers?: number
  todayNewUsers?: number
  activeRoles?: number
  inactiveRoles?: number
  avgPermissionsPerRole?: number
  todayNewRoles?: number
}

// 菜单项类型
export interface MenuItem {
  id: string
  title: string
  icon?: string
  path?: string
  children?: MenuItem[]
  permission?: string
}

// 艺人相关类型
export interface Artist {
  id: number
  name: string
  description?: string
  avatar?: string
  bannerImage?: string
  country?: string
  status: 'ACTIVE' | 'INACTIVE'
  createdAt: string
  updatedAt: string
  performances?: Performance[]
  _count?: {
    performances: number
    votes: number
    works: number
  }
  stats?: {
    performanceCount:number
    voteCount: number
    workCount: number
  }
}

export interface CreateArtistRequest {
  name: string
  description?: string
  avatar?: string
  bannerImage?: string
  country?: string
  status?: 'ACTIVE' | 'INACTIVE'
}

export interface UpdateArtistRequest {
  name?: string
  description?: string
  avatar?: string
  bannerImage?: string
  country?: string
  status?: 'ACTIVE' | 'INACTIVE'
}

// 场地相关类型
export interface Venue {
  id: number
  name: string
  description?: string
  address: string
  city: string
  country: string
  capacity?: number
  contactPhone?: string
  contactEmail?: string
  website?: string
  latitude?: number
  longitude?: number
  status: 'ACTIVE' | 'INACTIVE' | 'MAINTENANCE'
  createdAt: string
  updatedAt: string
  floors?: Floor[]
}

export interface Floor {
  id: number
  venueId: number
  name: string
  level?: number
  description?: string
  floorPlanUrl?: string
  status: 'ACTIVE' | 'INACTIVE'
  createdAt: string
  updatedAt: string
  venue?: Venue
}

// 演出相关类型
export interface Performance {
  id: number
  title: string
  description?: string
  venueId: number
  venue?: Venue
  floor?: string
  floorId?: number
  floorRef?: Floor
  startTime: string
  endTime: string
  maxCapacity?: number
  currentAttendance?: number
  status: 'SCHEDULED' | 'ONGOING' | 'COMPLETED' | 'CANCELLED'
  artistId: number
  artist?: Artist
  createdAt: string
  updatedAt: string
}

export interface CreatePerformanceRequest {
  artistId: number
  title: string
  description?: string
  venueId: number
  floor?: string
  floorId?: number
  startTime: string
  endTime: string
  maxCapacity?: number
}

export interface UpdatePerformanceRequest {
  title?: string
  description?: string
  venueId?: number
  floor?: string
  floorId?: number
  startTime?: string
  endTime?: string
  maxCapacity?: number
  status?: 'SCHEDULED' | 'ONGOING' | 'COMPLETED' | 'CANCELLED'
}

// 投票相关类型
export interface Vote {
  id: number
  userId: number
  artistId: number
  activityId: number
  voteCount: number
  createdAt: string
  user?: {
    id: number
    username: string
    realName?: string
    avatar?: string
  }
  artist?: {
    id: number
    name: string
    avatar?: string
  }
  activity?: {
    id: number
    name: string
  }
}

export interface VoteStatistics {
  totalVotes: number
  totalVoters: number
  averageVotesPerUser: number
  topArtists: Array<{
    artistId: number
    artistName: string
    voteCount: number
    voterCount: number
  }>
  dailyVotes: Array<{
    date: string
    voteCount: number
  }>
}

// 活动相关类型
export interface Activity {
  id: number
  name: string
  description?: string
  startTime: string
  endTime: string
  status: 'ACTIVE' | 'INACTIVE' | 'COMPLETED' | 'CANCELLED'
  bannerImage?: string
  rules?: string
  maxVotesPerUser: number
  createdAt: string
  updatedAt: string
  activityArtists?: ActivityArtist[]
  _count?: {
    activityArtists: number
    votes: number
  }
}

export interface ActivityArtist {
  id: number
  activityId: number
  artistId: number
  sortOrder: number
  createdAt: string
  artist: Artist
}

export interface ActivityVoteStatistics {
  activity: Activity
  artistStats: ActivityArtistStats[]
}

export interface ActivityArtistStats {
  artist: Artist
  totalVotes: number
  uniqueVoters: number
  sortOrder: number
}

// 内容相关类型
export interface FunFact {
  id: number
  title: string
  content: string
  artistId?: number
  artist?: {
    id: number
    name: string
    avatar?: string
  }
  isActive: boolean
  createdAt: string
  updatedAt: string
}

export interface CreateFunFactRequest {
  title: string
  content: string
  category?: string
  artistId?: number
  isActive?: boolean
}

export interface UpdateFunFactRequest {
  title?: string
  content?: string
  category?: string
  artistId?: number
  isActive?: boolean
}

export interface Badge {
  id: number
  name: string
  description?: string
  icon?: string
  type?: BadgeType
  conditionType?: BadgeConditionType
  conditionValue?: number
  earnedCount?: number
  createdAt: string
  updatedAt: string
}

export interface CreateBadgeRequest {
  name: string
  description?: string
  icon?: string
  type?: BadgeType
  conditionType?: BadgeConditionType
  conditionValue?: number
}

export interface UpdateBadgeRequest {
  name?: string
  description?: string
  icon?: string
  type?: BadgeType
  conditionType?: BadgeConditionType
  conditionValue?: number
}



// 作品相关类型
export interface Work {
  id: number
  artistId: number
  title: string
  duration?: string
  description?: string
  releaseDate?: string
  isRepresentative: boolean
  audioUrl?: string
  createdAt: string
  updatedAt: string
  artist?: {
    id: number
    name: string
    avatar?: string
  }
}

export interface CreateWorkRequest {
  artistId: number
  title: string
  duration?: string
  description?: string
  releaseDate?: string
  isRepresentative?: boolean
  audioUrl?: string
}

export interface UpdateWorkRequest {
  title?: string
  duration?: string
  description?: string
  releaseDate?: string
  isRepresentative?: boolean
  audioUrl?: string
} 